#include "HolePoint.h"
#include "BaseTooth.h"
#include "BaseBadPoint.h"

HolePoint::HolePoint(void)
{

}

HolePoint::~HolePoint(void)
{
	badPoint->autorelease();
}

HolePoint::HolePoint(BaseTooth::Position toothKind){
	kind = HOLE;
	op = 255;
    fixSpeed = 100;
	scheFlag = true;
    empty = false;
    finishFixed = false;
	switch(toothKind){
		case BaseTooth::UP_LEFT_ONE:
			badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t30006_png.png");
			badPoint->setPosition(ccp(98,217));
			addChild(badPoint);
			break;
		case BaseTooth::UP_LEFT_TWO:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t20004_png.png");
			badPoint->setPosition(ccp(122,217));
			addChild(badPoint);
            break;
		case BaseTooth::UP_LEFT_THREE:
			badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t10006_png.png");
			badPoint->setPosition(ccp(149,217));
			addChild(badPoint);
			break;
		case BaseTooth::UP_LEFT_FOUR:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t10006_png.png");
			badPoint->setPosition(ccp(179,217));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::UP_LEFT_FIVE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t20004_png.png");
			badPoint->setPosition(ccp(206,217));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::UP_LEFT_SIX:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t30006_png.png");
			badPoint->setPosition(ccp(230,217));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_ONE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t3_10006_png.png");
			badPoint->setPosition(ccp(98,179));
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_TWO:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t2_10004_png.png");
			badPoint->setPosition(ccp(123,174));
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_THREE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t1_10005_png.png");
			badPoint->setPosition(ccp(150,170));
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_FOUR:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t1_10005_png.png");
			badPoint->setPosition(ccp(178,170));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_FIVE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t2_10004_png.png");
			badPoint->setPosition(ccp(205,173));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_SIX:
            badPoint = CCSprite::create("img_sr_1280_720_damage_hole_t3_10006_png.png");
			badPoint->setPosition(ccp(230,179));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
	}
}

bool HolePoint::fixBadTooth(){
	if(scheFlag){
		schedule(schedule_selector(HolePoint::remove), 0.1f);
		scheFlag = false;
	}
	return true;
}

void HolePoint::remove(float dt)
{
		if(badPoint->getOpacity() > 0){
            
			badPoint->setOpacity(op);
            if(badPoint->getOpacity() - fixSpeed > 0)
                op -= fixSpeed;
            else{
                finishFixed = true;
                op = 0;
            }
		}
       CCLOG("scheduler removed %i", badPoint->getOpacity());
}

void HolePoint::stopFix(){	
	unschedule(schedule_selector(HolePoint::remove));
	scheFlag =true;
	CCLOG("scheduler removed");
}